package com.activity.adapter;

import android.content.Context;
import android.view.View;
import android.widget.TextView;

import com.activity.bean.AttanceRecordBean;
import com.donkingliang.groupedadapter.holder.BaseViewHolder;
import com.example.apple.ddhr_new.R;
import com.example.apple.ddhr_new.adapter.BaseAdapter;

import androidx.annotation.NonNull;
import butterknife.BindView;

public class MonthAdapter extends BaseAdapter<AttanceRecordBean> {



    public MonthAdapter(Context context) {
        super(context);
    }

    public boolean hasHeader = false;
    public MonthListener monthListener;
    public String beginTime;
    public String endTime;


    @Override
    public boolean hasHeader(int groupPosition) {
        return hasHeader;
    }

    @Override
    public int getHeaderLayout(int viewType) {
        return R.layout.header_define_query;
    }

    @Override
    public BaseViewHolder<AttanceRecordBean> getViewHolder(int viewType, View view) {

        if(viewType ==TYPE_CHILD)
        return new monthViewHolder(view);

        return null;
    }

    @Override
    public int getChildLayout(int viewType) {
        return R.layout.item_month_cell;
    }


    @Override
    public void onBindHeaderViewHolder(com.donkingliang.groupedadapter.holder.BaseViewHolder holder, int groupPosition) {
        holder.itemView.findViewById(R.id.tv_begin_time).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (monthListener != null) {
                    monthListener.beginTimeClick();
                }
            }
        });
        holder.itemView.findViewById(R.id.tv_end_time).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (monthListener != null) {
                    monthListener.endTimeClick();
                }
            }
        });
        holder.itemView.findViewById(R.id.tv_query).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (monthListener != null) {
                    monthListener.queryClick();
                }
            }
        });


        TextView begin =holder.itemView.findViewById(R.id.tv_begin_time);
        TextView end =holder.itemView.findViewById(R.id.tv_end_time);

        if(beginTime!=null){
            begin.setText(beginTime);
            begin.setTextColor(mContext.getResources().getColor(R.color.black));
        }

        if(endTime!=null){
            end.setText(endTime);
            end.setTextColor(mContext.getResources().getColor(R.color.black));
        }

    }


    public class monthViewHolder extends BaseViewHolder<AttanceRecordBean> {
        @BindView(R.id.tv_content)
        TextView tvContent;
        @BindView(R.id.tv_status)
        TextView tvStatus;
        public monthViewHolder(@NonNull View itemView) {
            super(itemView);
        }

        @Override
        public void setData(AttanceRecordBean data) {

            tvContent.setText(data.getCheckinaddtime()+"   "+data.getCheckinattendacetimespan_begintime()+"-"+data.getCheckinattendacetimespan_endtime()+"   "+data.getHours());


            tvStatus.setText(data.getCheckinstatusString());
        }
    }

    public interface MonthListener {

        public void beginTimeClick();

        public void endTimeClick();

        public void queryClick();
    }


}
